package filereaders;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;


/**
 * An object capable of reading tabbed
 * text files where data is ordered by row.
 * 
 * @author Paul Dannenberg
 * 
 */
public class TxtRowParser extends Parser {

    /**
     * Creates an object to read a specified
     * file.
     * @param file
     */
    public TxtRowParser(File file) {
        super(file);
    }

    /**
     * Creates an object to read from a 
     * scanner.
     * @param scanner
     */
    public TxtRowParser(Scanner scanner) {
        super(scanner);
    }

    @Override
    protected List<String> readSector(int indexOfData) {
        List<String> dataSector = new ArrayList<String>();
        Scanner fileScanner = loadScanner();
        while (fileScanner.hasNextLine()) {
            String line = fileScanner.nextLine();
            if (indexOfData == 0) {
                Scanner lineScanner = new Scanner(line);
                while (lineScanner.hasNext()) {
                    String dataPiece = lineScanner.next();
                    dataSector.add(dataPiece);
                }
            }
            indexOfData--;
        }
        return dataSector;
    }

    @Override
    public List<String> getOptions() {
        Parser columnParser = new TxtColumnParser(loadScanner());
        return columnParser.readSector(0);
    }
}
